<template>
    <div class="sendContainer">
        <!-- 勾选推送 -->
        <el-button
            type="primary"
            size="mini"
            class="sendNow"
            @click="sendFunc"
            :disabled="isSendNow"
            plain
            >{{ sendText }}</el-button
        >
    </div>
</template>

<script>
export default {
    name: "send",
    props: ["suoS", "multipleSelection", "loadTable", "waterType"],
    data() {
        return {
            isSendNow: true,
            sendText: "推送勾选数据",
        };
    },
    watch: {
        multipleSelection(newValue) {
            this.isSendNow = newValue.length ? false : true;
        },
    },
    methods: {
        // 勾选推送
        async sendFunc() {
            this.sendText = "推送中...";
            this.isSendNow = true;
            const { sendFun } = this.$parent;
            let { multipleSelection, waterType } = this;
            let ids = multipleSelection.map((item) =>
                waterType == 0 ? item.watermeterNo : item.waterNo
            );
            let { flag, message } = await sendFun(ids);
            let type = flag ? "success" : "success";
            this.sendText = "推送勾选数据";
            this.isSendNow = false;
            this.$message({ message: "推送成功", type });
            this.$emit("loadTable");
        },
    },
};
</script>

<style lang="scss" scoped>
.sendContainer {
    margin-left: 10px;
}
</style>
